<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        /*整体搜索区域的样式*/
         .search {
            margin: 20px;
            padding: 10px;
            border: 1px solid #ccc;
            border-radius: 5px;
            background-color: #f9f9f9;
        }

        /* 输入框标签的样式 */
      .search label {
            display: flex;
            align-items: center;
        }

        /* 输入框的样式 */
      .num {
            padding: 8px;
            border: 1px solid #ccc;
            border-radius: 3px;
            outline: none;
        }

        /* 显示快递单号的容器样式 */
      .con {
            margin-top: 5px;
            padding: 8px;
            border: 1px solid #ccc;
            border-radius: 3px;
            background-color: white;
            display: none;
        }
        
    </style>
</head>

<body>
    <div class="search">
        <div class="con"></div><label>快递单号:
            <input type="text" placeholder="请输入您的快递单号" class="num"></label>
    </div>
    <script>
        //通过css选择器获取元素
        let con = document.querySelector('.con');
        let numInput = document.querySelector('.num'); numInput.addEventListener('keyup', function () {
            if (this.value == '') {
                con.style.display = 'none';
            } else {
                con.style.display = 'block'; 
                con.innerText = this.value;//this指代触发input事件的那个元素 this.value获取<input>文本框当前输入的值
            }
        });
        numInput.addEventListener('blur', function () { 
            con.style.display = 'none'; });
        numInput.addEventListener('focus', function () {
            if (this.value !== '') {
                con.style.display = 'block';
            }
        });
    </script>
</body>

</html>